﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;//调用arraylist

namespace Csharp数据结构01
{
    //设计一个单例模式
    public class MonsterMange
    {
        //声明一个静态私有对象
        private static MonsterMange instance;

        internal static MonsterMange Instance
        {
            get 
            {
                if (instance==null)
                {
                    instance = new MonsterMange();
                }
                return instance;
            }

            //set ----不能改值
            //{
            //    instance = value;
            //}
        }
        public ArrayList monsterList;
        private MonsterMange() //把manage关闭起来
        {
             monsterList = new ArrayList();
        }

        

    }


    //monster类
    public class Monster
    {
        public string name;
        //构造函数
        public Monster(string name) 
        {
            this.name = name;

            //monster 一出生就自动添加

            MonsterMange.Instance.monsterList.Add(this); //this是指代自己，自己添加。一出生就添加到monsterlist 里面去了
        }

        //方法
        public void attack() 
        {
            Console.WriteLine("{0}攻击了",name);
        }
    }
}
